<template>
  <div>
    <el-form :inline="true" @submit.native.prevent>
      <el-form-item label="招生地区">
        <Province v-model="province" :show="false" @change="handleProvinceChange" />
      </el-form-item>
      <el-form-item label="院校名称">
        <AcademySelect v-model="academy" :multiple="false" />
      </el-form-item>
      <el-form-item label="科别">
        <SubjectCategory v-model="subject_category" />
      </el-form-item>
      <el-form-item label="招生批次">
        <AcademyLevel v-model="level" :options="targetList" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSearch">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="table.loading" :data="table.data" border>
      <el-table-column label="招生地区" prop="province" width="70" />
      <el-table-column label="招生批次" prop="level" width="100" />
      <el-table-column label="科别" prop="type" width="50" />
      <!--      <el-table-column label="院校代码" prop="academy_code" />-->
      <!--      <el-table-column label="院校招生代码" prop="academy_number" />-->
      <el-table-column label="院校名称" prop="academy_name" />
      <el-table-column label="专业招生代码" prop="major_number" />
      <el-table-column label="招生专业名称" prop="major_name" />
      <!--      <el-table-column label="专业标志" prop="major_sign" />-->
      <el-table-column label="计划数" prop="plan" width="50" />
      <el-table-column label="学费" prop="tuition" width="80" />
      <el-table-column label="学制" prop="regime" width="50" />
    </el-table>
    <WrapPagination>
      <el-pagination
        class="pagination"
        :current-page="table.page"
        :page-sizes="$store.state.app.pagination.sizes"
        :page-size="table.size"
        :layout="$store.state.app.pagination.layout"
        :total="table.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </WrapPagination>
  </div>
</template>

<script>
import { TableMixin } from '../../../components/mixin'
import { getPlanList } from '../../../api/query-log'
import { academyLevels } from '../../../api/app'

export default {
  name: 'Index',
  components: {
    Province: () => import('../../../components/AreaSelect'),
    SubjectCategory: () => import('../../../components/SubjectCategoryRadioGroup'),
    AcademySelect: () => import('../../../components/AcademySelect'),
    AcademyLevel: () => import('../../../components/AcademyLevel')
  },
  mixins: [TableMixin],
  data() {
    return {
      subject_category: '理科',
      province: '',
      academy: '',
      level: '',
      targetList: []
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    handleProvinceChange(province) {
      this.level = ''
      academyLevels({
        province: province
      }).then(res => {
        this.targetList = res
      })
    },
    getList() {
      this.wrapResourceList(getPlanList, {
        subject_category: this.subject_category,
        province: this.province,
        academy_code: this.academy,
        level: this.level
      })
    },
    handleSearch() {
      this.table.page = 1
      this.getList()
    }
  }
}
</script>

<style scoped>

</style>
